<?php

namespace App\Dao;

use App\Model\BalanceZhuBillsModel;

class BalanceZhuBillsDao extends BaseDao
{
    public static function builder_query($params = []): \Illuminate\Database\Eloquent\Builder
    {
        $query = BalanceZhuBillsModel::query();

        $query->when(checkIsHasField($params,'user_id'),function ($query)use ($params){
            $query->where('user_id',$params['user_id']);
        });


        return $query;
    }
    public static function moneyUpdate($user_id = 0,$nums = 0,$title = '')
    {
        UsersDao::builder_query([
            'user_id'=>$user_id
        ])->increment('balance_zhu',$nums);
        //添加记录
        self::builder_query()->create([
            'user_id'=>$user_id,
            'nums'=>$nums,
            'title'=>$title,
            'balance'=>UsersDao::builder_query([
                'user_id'=>$user_id
            ])->value('balance_zhu')
        ]);
    }


    public static function bills_lists($params = []): array
    {
        return self::builder_query($params)->get()->toArray();
    }
}
